n = int(input())
height = [int(x) for x in input().split(" ")]
left = 0
right = n - 1
maxArea = 0
while left < right:
    if height[left] <= height[right]:
        low = height[left]
        area = (right - left) * low
        maxArea = max(maxArea, area)
        while left < right and height[left] <= low:
            left += 1
    else:
        low = height[right]
        area = (right - left) * low
        maxArea = max(maxArea, area)
        while left < right and height[right] <= low:
            right -= 1
print(maxArea)